import { Context } from 'koa'
import Redis from 'ioredis'
import { select, success, update } from '../utils/index'

export class OptionController {
  static async getOptions(ctx: Context) {
    const { type } = ctx.request.body as any
    const [rows]: [any, any] = (await select('systems', { type })) as [any, any]
    if (!rows.length) {
      throw new Error('type传参错误')
    }
    ctx.body = success(ctx, rows)
  }
  static async updateSystemOptionToken(ctx: Context) {
    const { id } = ctx.request.body as any
    // const redis = new Redis({port: 6379,host: '127.0.0.1'});
    // const result = await redis.get('arrList')
    const token =
      'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjcsInJuU3RyIjoiQWJSdDVJR0lFa1V5RnpVQ2hNVmFESEtGZUppZVV2ekkiLCJ1c2VyIjoie1wiaWRcIjo3LFwiaXNUZW5hbnRBZG1pblwiOjAsXCJ0ZW5hbnRJZFwiOlwiXCIsXCJ1c2VyTmFtZVwiOlwiMTUxNTgxMDg2MDFcIixcInVzZXJOaWNrTmFtZVwiOlwi5bqE5oiQXCJ9In0.zLs-GaFfd4WemIpGw6zM9UnRARQiknuHxVp1PKCBfJI'
    await update('systems', { id }, { token })
    ctx.body = success(ctx, { token })
  }
}
